1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module gsk.RenderNode; 26 27 private import cairo.Context; 28 private import glib.Bytes; 29 private import glib.ErrorG; 30 private import glib.GException; 31 private import glib.MemorySlice; 32 private import glib.Str; 33 private import gobject.ObjectG; 34 private import graphene.Rect; 35 private import gsk.c.functions; 36 public import gsk.c.types; 37 private import linker.Loader; 38 39 40 /** 41 * `GskRenderNode` is the basic block in a scene graph to be 42 * rendered using [class@Gsk.Renderer]. 43 * 44 * Each node has a parent, except the top-level node; each node may have 45 * children nodes. 46 * 47 * Each node has an associated drawing surface, which has the size of 48 * the rectangle set when creating it. 49 * 50 * Render nodes are meant to be transient; once they have been associated 51 * to a [class@Gsk.Renderer] it's safe to release any reference you have on 52 * them. All [class@Gsk.RenderNode]s are immutable, you can only specify their 53 * properties during construction. 54 */ 55 public class RenderNode 56 { 57 /** the main Gtk struct */ 58 protected GskRenderNode* gskRenderNode; 59 protected bool ownedRef; 60 61 /** Get the main Gtk struct */ 62 public GskRenderNode* getRenderNodeStruct(bool transferOwnership = false) 63 { 64 if (transferOwnership) 65 ownedRef = false; 66 return gskRenderNode; 67 } 68 69 /** the main Gtk struct as a void* */ 70 protected void* getStruct() 71 { 72 return cast(void*)gskRenderNode; 73 } 74 75 /** 76 * Sets our main struct and passes it to the parent class. 77 */ 78 public this (GskRenderNode* gskRenderNode, bool ownedRef = false) 79 { 80 this.gskRenderNode = gskRenderNode; 81 this.ownedRef = ownedRef; 82 } 83 84 ~this () 85 { 86 if ( Linker.isLoaded(LIBRARY_GSK[0]) && ownedRef ) 87 gsk_render_node_unref(gskRenderNode); 88 } 89 90 91 /** */ 92 public static GType getType() 93 { 94 return gsk_render_node_get_type(); 95 } 96 97 /** 98 * Loads data previously created via [method@Gsk.RenderNode.serialize]. 99 * 100 * For a discussion of the supported format, see that function. 101 * 102 * Params: 103 * bytes = the bytes containing the data 104 * errorFunc = Callback on parsing errors 105 * userData = user_data for @error_func 106 * 107 * Returns: a new `GskRenderNode` 108 */ 109 public static RenderNode deserialize(Bytes bytes, GskParseErrorFunc errorFunc, void* userData) 110 { 111 auto __p = gsk_render_node_deserialize((bytes is null) ? null : bytes.getBytesStruct(), errorFunc, userData); 112 113 if(__p is null) 114 { 115 return null; 116 } 117 118 return ObjectG.getDObject!(RenderNode)(cast(GskRenderNode*) __p, true); 119 } 120 121 /** 122 * Draw the contents of @node to the given cairo context. 123 * 124 * Typically, you'll use this function to implement fallback rendering 125 * of `GskRenderNode`s on an intermediate Cairo context, instead of using 126 * the drawing context associated to a [class@Gdk.Surface]'s rendering buffer. 127 * 128 * For advanced nodes that cannot be supported using Cairo, in particular 129 * for nodes doing 3D operations, this function may fail. 130 * 131 * Params: 132 * cr = cairo context to draw to 133 */ 134 public void draw(Context cr) 135 { 136 gsk_render_node_draw(gskRenderNode, (cr is null) ? null : cr.getContextStruct()); 137 } 138 139 /** 140 * Retrieves the boundaries of the @node. 141 * 142 * The node will not draw outside of its boundaries. 143 * 144 * Params: 145 * bounds = return location for the boundaries 146 */ 147 public void getBounds(out Rect bounds) 148 { 149 graphene_rect_t* outbounds = sliceNew!graphene_rect_t(); 150 151 gsk_render_node_get_bounds(gskRenderNode, outbounds); 152 153 bounds = ObjectG.getDObject!(Rect)(outbounds, true); 154 } 155 156 /** 157 * Returns the type of the @node. 158 * 159 * Returns: the type of the `GskRenderNode` 160 */ 161 public GskRenderNodeType getNodeType() 162 { 163 return gsk_render_node_get_node_type(gskRenderNode); 164 } 165 166 alias doref = ref_; 167 /** 168 * Acquires a reference on the given `GskRenderNode`. 169 * 170 * Returns: the `GskRenderNode` with an additional reference 171 */ 172 public RenderNode ref_() 173 { 174 auto __p = gsk_render_node_ref(gskRenderNode); 175 176 if(__p is null) 177 { 178 return null; 179 } 180 181 return ObjectG.getDObject!(RenderNode)(cast(GskRenderNode*) __p, true); 182 } 183 184 /** 185 * Serializes the @node for later deserialization via 186 * gsk_render_node_deserialize(). No guarantees are made about the format 187 * used other than that the same version of GTK will be able to deserialize 188 * the result of a call to gsk_render_node_serialize() and 189 * gsk_render_node_deserialize() will correctly reject files it cannot open 190 * that were created with previous versions of GTK. 191 * 192 * The intended use of this functions is testing, benchmarking and debugging. 193 * The format is not meant as a permanent storage format. 194 * 195 * Returns: a `GBytes` representing the node. 196 */ 197 public Bytes serialize() 198 { 199 auto __p = gsk_render_node_serialize(gskRenderNode); 200 201 if(__p is null) 202 { 203 return null; 204 } 205 206 return new Bytes(cast(GBytes*) __p, true); 207 } 208 209 /** 210 * Releases a reference on the given `GskRenderNode`. 211 * 212 * If the reference was the last, the resources associated to the @node are 213 * freed. 214 */ 215 public void unref() 216 { 217 gsk_render_node_unref(gskRenderNode); 218 } 219 220 /** 221 * This function is equivalent to calling [method@Gsk.RenderNode.serialize] 222 * followed by [func@GLib.file_set_contents]. 223 * 224 * See those two functions for details on the arguments. 225 * 226 * It is mostly intended for use inside a debugger to quickly dump a render 227 * node to a file for later inspection. 228 * 229 * Params: 230 * filename = the file to save it to. 231 * 232 * Returns: %TRUE if saving was successful 233 * 234 * Throws: GException on failure. 235 */ 236 public bool writeToFile(string filename) 237 { 238 GError* err = null; 239 240 auto __p = gsk_render_node_write_to_file(gskRenderNode, Str.toStringz(filename), &err) != 0; 241 242 if (err !is null) 243 { 244 throw new GException( new ErrorG(err) ); 245 } 246 247 return __p; 248 } 249 }